home *** CD-ROM | disk | FTP | other *** search
/ Champak 64 / Volume 64 - JOGO DISK .iso / Games / the_best_every_day.swf / scripts / __Packages / MiniGame.as < prev    next >
Text File  |  2008-04-10  |  5KB  |  152 lines

  1. class MiniGame extends MovieClip
  2. {
  3.    var DEFAULT_STATE = "update";
  4.    var TIME_RANDOM = 200;
  5.    var aKeyPossible = ["81","87","82","84","80","76","75","74","72","71","70","68","83"];
  6.    function MiniGame()
  7.    {
  8.       super();
  9.       _global.C.oGame.mcMiniGame = _global.C.oGame.mcGame.MiniGame;
  10.       _global.MiniGame = this;
  11.       this.keyListener = new Object();
  12.       this.nKeyUsed = 0;
  13.       this.nTimeWait = 0;
  14.       this.sEtat = "Wait";
  15.       this.setVars();
  16.    }
  17.    function update()
  18.    {
  19.       this[this.sEtat]();
  20.    }
  21.    function setVars()
  22.    {
  23.       this.nTimeToWait = _global.C.oGame.nTimeBetweenMG + random(this.TIME_RANDOM);
  24.    }
  25.    function Wait()
  26.    {
  27.       this.nTimeWait = this.nTimeWait + 1;
  28.       if(this.nTimeWait > this.nTimeToWait && _global.C.oGame.oLevel.oPatrick.sState == "Move")
  29.       {
  30.          this.nTimeWait = 0;
  31.          this.ActionDone = 0;
  32.          this.nKeyToUse = 0;
  33.          this.setVars();
  34.          this.PrepareStage();
  35.          var _loc3_ = random(100);
  36.          if(_loc3_ < 33 && this.nElementToUse != 1)
  37.          {
  38.             this.RepeatAction = 15;
  39.             this.nElementToUse = 1;
  40.          }
  41.          else if(_loc3_ < 66 && this.nElementToUse != 2)
  42.          {
  43.             this.RepeatAction = 7;
  44.             this.nElementToUse = 2;
  45.          }
  46.          else if(this.nElementToUse != 3)
  47.          {
  48.             this.RepeatAction = 4;
  49.             this.nElementToUse = 3;
  50.          }
  51.          else
  52.          {
  53.             this.RepeatAction = 7;
  54.             this.nElementToUse = 2;
  55.          }
  56.          this.mcRef.gotoAndStop(this.nElementToUse);
  57.          this.CreateArray();
  58.          this.sEtat = "Pass";
  59.       }
  60.    }
  61.    function CreateArray()
  62.    {
  63.       this.aKeyToActive = new Array();
  64.       var _loc3_ = Tools.doCopyArray(this.aKeyPossible);
  65.       while(this.aKeyToActive.length < this.nElementToUse)
  66.       {
  67.          var _loc2_ = random(_loc3_.length);
  68.          this.mcRef["Key" + this.aKeyToActive.length].Key_txt.text = String.fromCharCode(_loc3_[_loc2_]);
  69.          if(this.aKeyToActive.length == 0)
  70.          {
  71.             this.mcRef.Window_txt.text += String(this.mcRef["Key" + this.aKeyToActive.length].Key_txt.text);
  72.             this.mcRef["Key" + this.aKeyToActive.length].gotoAndStop(2);
  73.          }
  74.          else
  75.          {
  76.             this.mcRef.Window_txt.text += ", " + String(this.mcRef["Key" + this.aKeyToActive.length].Key_txt.text);
  77.          }
  78.          this.aKeyToActive.push(_loc3_[_loc2_]);
  79.          _loc3_.splice(_loc2_,1);
  80.       }
  81.    }
  82.    function PrepareStage()
  83.    {
  84.       _global.C.oGame.bMiniGame = true;
  85.       _global.C.oGame.oLevel.oPatrick.mc._parent._parent.mcSpongebob.gotoAndStop("OffScreen");
  86.       _global.C.oGame.mcGame.MiniGame.gotoAndPlay("appear");
  87.       this.mcRef = _global.C.oGame.mcGame.MiniGame.GameScreen;
  88.       this.mcRef.Barre._xscale = 0;
  89.       this.CreateOnPress();
  90.    }
  91.    function Pass()
  92.    {
  93.       if(this.nKeyUsed != 0)
  94.       {
  95.          this.CheckActionEnter();
  96.          this.nKeyUsed = 0;
  97.          if(this.ActionDone == this.RepeatAction)
  98.          {
  99.             this.Succead();
  100.          }
  101.       }
  102.    }
  103.    function CheckActionEnter()
  104.    {
  105.       if(this.nKeyUsed == this.aKeyToActive[this.nKeyToUse])
  106.       {
  107.          this.mcRef["Key" + this.nKeyToUse].gotoAndStop(1);
  108.          this.nKeyToUse = this.nKeyToUse + 1;
  109.          this.mcRef.Barre._xscale = Number((this.nKeyToUse + this.ActionDone * this.nElementToUse) / (this.RepeatAction * this.nElementToUse) * 100);
  110.          if(this.nKeyToUse >= this.aKeyToActive.length)
  111.          {
  112.             this.nKeyToUse = 0;
  113.             this.ActionDone = this.ActionDone + 1;
  114.          }
  115.          this.mcRef["Key" + this.nKeyToUse].gotoAndStop(2);
  116.       }
  117.    }
  118.    function CheckButtonEnter(_code)
  119.    {
  120.       if(_code == this.aKeyToActive[this.nKeyToUse])
  121.       {
  122.          this.mcRef["Key" + this.nKeyToUse].gotoAndStop(3);
  123.       }
  124.    }
  125.    function Succead()
  126.    {
  127.       this.sEtat = "Wait";
  128.       this.mcRef.gotoAndStop(Number(this.mcRef._currentframe + 3));
  129.       _global.C.oGame.AjustScore(_global.C.oGame.nMiniFunds,"Funds");
  130.       _global.C.oGame.oLevel.oPatrick.mc._parent._parent.mcSpongebob.gotoAndStop("inScreen");
  131.       _global.C.oGame.mcGame.MiniGame.gotoAndPlay("disapear");
  132.       _global.C.oGame.bMiniGame = false;
  133.       this.ClearControls();
  134.    }
  135.    function CreateOnPress()
  136.    {
  137.       this.keyListener.onKeyUp = function()
  138.       {
  139.          _global.MiniGame.nKeyUsed = Key.getCode();
  140.       };
  141.       this.keyListener.onKeyDown = function()
  142.       {
  143.          _global.MiniGame.CheckButtonEnter(Key.getCode());
  144.       };
  145.       Key.addListener(this.keyListener);
  146.    }
  147.    function ClearControls()
  148.    {
  149.       Key.removeListener(this.keyListener);
  150.    }
  151. }
  152.